import { StrictMode } from "react";
import { createRoot } from "react-dom/client";
import { RouterProvider } from "react-router/dom";
import { useMount } from "react-use";
import routes from "./routes";
import useMeStore from "./store/me";

import "./index.css";
import useThemeStore from "./store/theme";

function Root() {
  const meStore = useMeStore();
  const themeStore = useThemeStore();

  useMount(() => {
    themeStore.init();
    meStore.loadMe();
  });

  return <RouterProvider router={routes} />;
}

const root = document.getElementById("root");
if (root) {
  createRoot(root).render(
    <StrictMode>
      <Root />
    </StrictMode>,
  );
}
